﻿#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<set>
using namespace std;

//int main()
//{
//	int n = 0;
//	string s;
//	cin >> n >> s;
//	int sum[2] = { 0 }; // 统计字符串中所有 0 和 1 的个数
//	for (auto ch : s)
//	{
//		sum[ch - '0']++;
//	}
//	int left = 0, right = 0, ret = 0, half = n / 2;
//	int count[2] = { 0 }; // 统计窗⼝内 0 和 1 的个数
//	while (right < n - 1)
//	{
//		count[s[right] - '0']++;
//		while (right - left + 1 > half)
//		{
//			count[s[left++] - '0']--;
//		}
//		if (right - left + 1 == half)
//		{
//			if (count[0] * 2 == sum[0] && count[1] * 2 == sum[1])
//			{
//				ret += 2;
//			}
//		}
//		right++;
//	}
//	cout << ret << endl;
//	return 0;
//}

class Solution {
public:
    vector<string> findWords(vector<string>& words)
    {
        vector<string> v{ "qwertyuiop","asdfghjkl","zxcvbnm" };//三行已知字符串
        //unordered_map<char, int> m(v[0].begin(), v[0].end());
        //set<char> s(v[0].begin(), v[0].end());
        string str = "aashdgghskkkjh";
        set<char> s(str.begin(), str.end());
        vector<unordered_map<char, int>> temp(3, unordered_map<char, int>());//把三行字符串映射进三张unordered_map表中
        for (int i = 0; i < 3; i++)
        {
            for (auto& c : v[i])
            {
                temp[i][c]++;
            }
        }
        vector<string> ret;
        for (auto& word : words)//枚举每一个串
        {
            bool flag1 = true, flag2 = true, flag3 = true;
            for (auto c : word)//枚举每一个字符
            {
                c = tolower(c);//转成小写
                flag1 &= temp[0][c];
                flag2 &= temp[1][c];
                flag3 &= temp[2][c];
            }
            if (flag1 || flag2 || flag3)
            {
                ret.push_back(word);
            }
        }
        return ret;
    }

    int numJewelsInStones(string jewels, string stones)
    {
        unordered_map<char, int> m;
        for (auto& c : jewels)
        {
            m[c]++;
        }
        int count = 0;
        //set<char> s(stones.begin(),stones.end());//直接使用set去重
        for (auto c : stones)
        {
            if (m[c] == 1)
            {
                count++;
            }
        }
        return count;
    }
};

int main()
{
    Solution S;
    vector<string> v{ "Hello","Alaska","Dad","Peace" };
    S.findWords(v);
    return 0;
}